package com.turman.common.db

import androidx.lifecycle.LiveData
import androidx.room.*

@Dao
interface UserDao {

    @Query(value="select * from db_user")
    fun getAll():List<DbUser?>?

    @Query("SELECT * FROM db_user WHERE uid IN (:userIds)")
    fun loadAllByIds(userIds:IntArray?):LiveData<List<DbUser?>?> //根据uid查询

    @Query(
        "SELECT * from db_user WHERE uname LIKE :name AND " +
                "age LIKE :age LIMIT 1")  //注意limit是返回结果列表中的前几条
    fun findByName(name:String?,age:Int):DbUser?

    @Query("select * from db_user where uid like :id")
    fun getUserById(id:Int?):DbUser

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    fun insertAll(vararg users:DbUser?)

    @Delete
    fun delete(user:DbUser)

    @Query("delete from db_user WHERE uid is not 0")
    fun deleteAll()

    @Update(onConflict = OnConflictStrategy.REPLACE)
    fun update(user:DbUser)  //更新，上面的策略是如出现冲突则替换

    @Query("select * from tmpBean")  //查询视图的实例
    fun getUSerBook():List<TempBean>
}